{% extends 'accounts/base.html' %}

{% load form_extras %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">{{ title }}</h1>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-bars"></i> {{ title }}
                </h5>
            </div>
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="{{ form.name.id_for_label }}" class="form-label">菜单名称</label>
                                {{ form.name|add_class:"form-control" }}
                                {% if form.name.errors %}
                                    <div class="text-danger">{{ form.name.errors }}</div>
                                {% endif %}
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="{{ form.order.id_for_label }}" class="form-label">排序</label>
                                {{ form.order|add_class:"form-control" }}
                                {% if form.order.errors %}
                                    <div class="text-danger">{{ form.order.errors }}</div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="{{ form.url.id_for_label }}" class="form-label">URL</label>
                                {{ form.url|add_class:"form-control" }}
                                {% if form.url.errors %}
                                    <div class="text-danger">{{ form.url.errors }}</div>
                                {% endif %}
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="{{ form.icon.id_for_label }}" class="form-label">图标</label>
                                {{ form.icon|add_class:"form-control" }}
                                {% if form.icon.errors %}
                                    <div class="text-danger">{{ form.icon.errors }}</div>
                                {% endif %}
                                <div class="form-text">使用 FontAwesome 图标类名，例如: fas fa-home</div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="{{ form.parent.id_for_label }}" class="form-label">父菜单</label>
                                {{ form.parent|add_class:"form-control" }}
                                {% if form.parent.errors %}
                                    <div class="text-danger">{{ form.parent.errors }}</div>
                                {% endif %}
                                <div class="form-text">选择父菜单，不选则为顶级菜单（应用）</div>
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">状态</label>
                                <div class="form-check">
                                    {{ form.is_active|add_class:"form-check-input" }}
                                    <label for="{{ form.is_active.id_for_label }}" class="form-check-label">是否启用</label>
                                </div>
                                {% if form.is_active.errors %}
                                    <div class="text-danger">{{ form.is_active.errors }}</div>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> 保存
                        </button>
                        <a href="{% url 'accounts:menu_list' %}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> 返回
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-info-circle"></i> 帮助信息
                </h5>
            </div>
            <div class="card-body">
                <h6>菜单层级说明：</h6>
                <ul>
                    <li><strong>顶级菜单</strong>：不选择父菜单的菜单为应用入口</li>
                    <li><strong>子菜单</strong>：选择父菜单的菜单为其子菜单</li>
                    <li><strong>层级</strong>：菜单可以有任意层级，建议不超过3层</li>
                </ul>
                
                <h6>菜单命名建议：</h6>
                <ul>
                    <li>顶级菜单建议使用应用名称，如"用户管理"</li>
                    <li>子菜单使用具体功能名称，如"用户列表"、"角色管理"</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %}